#!/usr/bin/python
# -*- coding: UTF-8 -*-  

"TestDecorator"

__author__ = "Wang Zhe"

import functools

def log(func):
	@functools.wraps(func)
	def wrapper(*args,**kw):
		print('begin call %s():' % (func.__name__))
		func(*args,**kw)
		print('end call %s():' % func.__name__)
		return 
	return wrapper

def log(param):
	if(type(param) == type(log)):
		func = param
		def wrapper(*args,**kw):
			print('begin call %s():' % (func.__name__))
			ret = func(*args,**kw)
			print('end call %s():' % func.__name__)
			return ret
		return wrapper
	elif(type(param) == type('')):
		text = param
		def decorator(func):
			def wrapper(*args,**kw):
				print('begin %s %s():' % (text,func.__name__))
				ret = func(*args,**kw)
				print('end %s %s():' % (text,func.__name__))
				return ret
			return wrapper
		return decorator


@log
def now():
	print('now():2017-7-15')

@log('execute')
def after():
	print('after():2017-7-16')

def main():
	now()
	after()

if __name__ == '__main__':
	main()